package com.echo.code.thread.mode.observer;

import java.util.concurrent.TimeUnit;

/**
 * TestCase Created by baiyap on 2018/9/24.
 */
public class TestCase {

  public static void main(String[] args) {
    final LifeHandler handler = new LifeHandler() {
      @Override
      public void onStart(Thread thread) {
        System.out.println(thread.getName() + " starting...");
      }

      @Override
      public void onDone(Thread thread) {
        System.out.println(thread.getName() + " done.");
      }

      @Override
      public void onError(Thread thread, Throwable throwable) {
        System.out.println(thread.getName() + " error.");
        System.out.println(throwable.getMessage());
      }
    };
    new ConcreteObserver<Void>(handler, () -> {
      try {
        TimeUnit.SECONDS.sleep(20);
      } catch (InterruptedException e) {
      }
      throw new NullPointerException("task error");
    }).start();
  }
}
